var t = require("../../../../@babel/runtime/helpers/typeof"), e = getApp();

Page({
    data: {
        language: "",
        show1: !1,
        show2: !1,
        show3: !1,
        show4: !1,
        nickname: "",
        avatar: "",
        summarizing: {
            goods_queue_count: 0,
            store_queue_count: 0,
            cashier_queue_count: 0
        },
        getDataApi: "",
        rewardList: [],
        activeName: "shop",
        chooseName: "queue",
        status: "",
        chooseId: "",
        chooseRatio: "",
        msg: "",
        typeData: {},
        WXtitle: "",
        items: {},
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        type: "",
        convertType: "",
        convertTypeId: 0,
        convertTypeUnit: 0,
        convertTypeExchange_count: 0,
        exchangeLogs: {}
    },
    onLoad: function(t) {
        this.checkrouter(), this.getTitle(), this.getData(this.data.activeName, "plugin.share-chain.frontend.queue.getList"), 
        this.getUser(), this.getHomeInfo();
    },
    checkrouter: function() {
        try {
            var e = function() {
                for (var t = wx.getStorageSync("yz_basic_info"), e = t.popularize_page.mini.vue_route, a = 0; a < e.length; a++) if ("RewardQueue" == e[a]) return console.log(t.popularize_page.mini.mini_url + "跳转的路径"), 
                wx.showToast({
                    title: "未开启推广权限",
                    duration: 1e3,
                    icon: "none",
                    success: function() {
                        setTimeout(function() {
                            wx.redirectTo({
                                url: t.popularize_page.mini.mini_url
                            });
                        }, 1e3);
                    }
                }), {
                    v: void 0
                };
            }();
            if ("object" === t(e)) return e.v;
        } catch (t) {
            console.log(t);
        }
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.data.isLoadMore ? this.getMoreData() : wx.showToast({
            title: "没有更多数据",
            icon: "none"
        });
    },
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    toDetail: function() {
        wx.navigateTo({
            url: "/packageB/member/enterprise/reward_detail/reward_detail"
        });
    },
    toProcess: function(t) {
        var e = t.currentTarget.dataset.item || t.target.dataset.item;
        wx.navigateTo({
            url: "/packageB/member/enterprise/RewardProcess/RewardProcess?source_code=" + this.data.activeName + "&queue_id=" + e.id
        });
    },
    showComplete: function(t) {
        var e = t.currentTarget.dataset.item || t.target.dataset.item;
        e.show = !0;
        for (var a = this.data.rewardList, o = 0; o < a.length; o++) a[o].id == e.id && (a[o].show = !0);
        this.setData({
            rewardList: a
        });
    },
    leaveOut: function() {
        this.setData({
            show3: !1
        });
    },
    getTitle: function() {
        var t = e.getNetAddresss("plugin.share-chain.frontend.plugin-name.index");
        e._getNetWork({
            url: t,
            success: function(t) {
                1 === t.data.result ? (t.data = t.data.data, wx.setNavigationBarTitle({
                    title: t.data.plugin_name ? t.data.plugin_name : ""
                })) : wx.showToast({
                    title: t.data.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    chooseType: function(t) {
        var e = t.target.dataset.point || t.currentTarget.dataset.point, a = this.data.typeData;
        1 === e.code ? this.setData({
            convertType: a.modules.point.name,
            convertTypeId: a.modules.point.code,
            convertTypeUnit: a.modules.point.unit,
            convertTypeExchange_count: a.modules.point.exchange_count
        }) : 2 === e.code && this.setData({
            convertType: a.modules.love.name,
            convertTypeId: a.modules.love.code,
            convertTypeUnit: a.modules.love.unit,
            convertTypeExchange_count: a.modules.love.exchange_count
        });
    },
    exchange: function(t) {
        var a = this, o = t.currentTarget.dataset.item || t.target.dataset.item;
        this.setData({
            chooseId: o.id,
            convertType: "",
            convertTypeId: 0,
            convertTypeUnit: 0,
            convertTypeExchange_count: 0
        });
        var s = e.getNetAddresss("plugin.share-chain.frontend.exchange.index");
        s += "&source_code=" + this.data.activeName + "&queue_id=" + o.id, e._getNetWork({
            url: s,
            success: function(t) {
                1 === t.data.result ? (t.data = t.data.data, a.setData({
                    show3: !0,
                    typeData: t.data
                })) : wx.showToast({
                    title: t.data.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    SureExchange: function() {
        var t = this, a = e.getNetAddresss("plugin.share-chain.frontend.exchange.handle");
        a += "&source_code=" + this.data.activeName + "&queue_id=" + this.data.chooseId + "&exchange_code=" + this.data.convertTypeId, 
        e._getNetWork({
            url: a,
            success: function(e) {
                1 === e.data.result ? (e.data = e.data.data, t.setData({
                    show3: !1
                }), t.getData(t.data.activeName, "plugin.share-chain.frontend.queue.getList"), wx.showToast({
                    title: e.data.msg,
                    icon: "none"
                })) : (t.setData({
                    show3: !1
                }), wx.showToast({
                    title: e.data.msg,
                    icon: "none"
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    endReward: function() {
        this.setData({
            show4: !1
        });
    },
    exchangeLog: function(t) {
        var a = this, o = t.currentTarget.dataset.item || t.target.dataset.item, s = e.getNetAddresss("plugin.share-chain.frontend.exchange.log");
        s += "&source_code=" + this.data.activeName + "&queue_id=" + o.id, e._getNetWork({
            url: s,
            success: function(t) {
                1 === t.data.result ? (t.data = t.data.data, a.setData({
                    show4: !0,
                    exchangeLogs: t.data
                })) : wx.showToast({
                    title: t.data.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    luckyDraw: function(t) {
        var e = t.currentTarget.dataset.item || t.target.dataset.item;
        this.setData({
            show1: !0,
            chooseId: e.id,
            chooseRatio: e.ratio
        });
    },
    sureTake: function(t) {
        var a = this, o = e.getNetAddresss("plugin.share-chain.frontend.lucky.handle");
        o += "&source_code=" + this.data.activeName + "&queue_id=" + this.data.chooseId, 
        e._getNetWork({
            url: o,
            success: function(t) {
                1 === t.data.result ? (t.data = t.data.data, a.setData({
                    show1: !1,
                    show2: !0,
                    msg: t.data.msg
                }), a.getData(a.data.activeName, "plugin.share-chain.frontend.queue.getList")) : (a.setData({
                    show1: !1
                }), wx.showToast({
                    title: t.data.msg,
                    icon: "none"
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    sureTakere: function() {
        this.setData({
            show1: !1
        });
    },
    getUser: function() {
        var t = this, a = e.getNetAddresss("plugin.share-chain.frontend.member.getInfo");
        e._getNetWork({
            url: a,
            success: function(e) {
                1 === e.data.result ? (e.data = e.data.data, t.setData({
                    nickname: e.data.nickname,
                    avatar: e.data.avatar
                })) : wx.showToast({
                    title: e.data.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getHomeInfo: function() {
        var t = this, a = e.getNetAddresss("plugin.share-chain.frontend.center.statistics");
        e._getNetWork({
            url: a,
            success: function(e) {
                1 === e.data.result ? (e.data = e.data.data, t.setData({
                    summarizing: e.data
                })) : wx.showToast({
                    title: e.data.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    handleClick1: function(t) {
        0 == t.detail.index ? (this.getData(this.data.activeName, "plugin.share-chain.frontend.queue.getList"), 
        this.setData({
            chooseName: "queue"
        })) : 1 == t.detail.index && (this.setData({
            chooseName: "record"
        }), this.getData("", "plugin.share-chain.frontend.log.getList"));
    },
    handleClick: function(t) {
        0 == t.detail.index ? this.setData({
            activeName: "shop"
        }) : 1 == t.detail.index ? this.setData({
            activeName: "store"
        }) : 2 == t.detail.index && this.setData({
            activeName: "cashier"
        }), this.getData(this.data.activeName, "plugin.share-chain.frontend.queue.getList");
    },
    getData: function(t, a) {
        var o = this;
        this.setData({
            getDataApi: a,
            status: t
        });
        var s = e.getNetAddresss(a);
        s += "&source_code=" + t, e._getNetWork({
            url: s,
            success: function(t) {
                1 === t.data.result ? (t.data = t.data.data, o.setData({
                    isLoadMore: !0,
                    total_page: t.data.last_page,
                    rewardList: t.data.data
                }), o.data.total_page || o.setData({
                    total_page: 0
                })) : wx.showToast({
                    title: t.data.msg,
                    icon: "none",
                    duration: 1500,
                    success: function() {
                        setTimeout(function() {
                            wx.navigateTo({
                                url: "/packageG/pages/member/extension/extension"
                            });
                        }, 1500);
                    }
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var t = this;
        this.setData({
            isLoadMore: !1
        });
        var a = e.getNetAddresss(this.data.getDataApi), o = this.data.page + 1;
        this.setData({
            page: o
        }), this.data.status ? a += "&source_code=" + status + "&page=" + this.data.page : a += "&page=" + this.data.page, 
        this.data.page >= this.data.total_page || e._getNetWork({
            url: a,
            success: function(e) {
                if (1 === e.data.result) {
                    e.data = e.data.data;
                    var a = t.data.rewardList.concat(e.data.data);
                    t.setData({
                        isLoadMore: !0,
                        rewardList: a
                    });
                } else {
                    var o = t.data.page - 1;
                    t.setData({
                        page: o,
                        isLoadMore: !1
                    });
                }
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});